home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Original Shareware 1.1
/
The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso
/
19
/
madtrb11.zip
/
CHOICES.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-07-13
|
3KB
|
128 lines
program choices;
{
This program demonstrates how choices from a menu can be made by pointing
(like Lotus' 1-2-3) instead of entering a number.
Source: "Choices: A Generalized Menu Technique", TUG Lines Volume I Issue 3
Author: Barry Abrahamsen
Application: All systems (some modification required)
}
const
up_arrow = #$82; {the values for the ADVANTAGE}
down_arrow = #$8A;
norm_video = #$02;
rev_video = #$01;
max_choices = 3; {one less than the actual number of choices}
cr = #$0d;
bell = #$07;
type
choice_type = record { more information could be included here}
row : integer; { and that information returned by GET_CHOICE,}
column : integer; { instead of just the position of the choice in}
description : string[60];{ the array }
end;
var
choice : array[0..max_choices] of choice_type;
result : integer;
procedure beep;
begin
write(bell);
end;
procedure turn_on(choice : choice_type); {highlights a menu choice}
begin
gotoxy(choice.column, choice.row);
write(rev_video, choice.description, norm_video);
end;
procedure turn_off(choice : choice_type); {cancels the highlighting}
begin
gotoxy(choice.column, choice.row);
write(norm_video, choice.description, rev_video);
end;
procedure initialize_choices; { puts the descriptions of the menu choices}
{ and their location on the screen in an }
var { array }
i :integer;
begin
for i := 0 to max_choices do
with choice[i] do
begin
row := i + 5; {each choice on a different row}
column := 5;
description := 'This is a choice'; {all choice descriptions the same}
end;
end;
procedure display_choices;
var
i : integer;
begin
clrscr;
for i := 0 to max_choices do
with choice[i] do
begin
gotoxy(column, row);
write(description);
end;
turn_on(choice[0]);
end; {display_choices}
function get_choice : integer;
var
c : char;
current, last : integer;
begin
current := 0;
last := 0;
repeat {loop until they hit the RETURN key}
read(kbd, c);
case c of
up_arrow, ^X : begin {^X and ^E usage reversed from }
last := current; { WordStar }
current := last + 1;
end;
down_arrow, ^E : begin
last := current;
if last <> 0 then
current := last - 1
else
current := max_choices;
end;
else if c <> cr then beep;
end; {case}
if c in [up_arrow, down_arrow, ^E, ^X] then
begin
current := current mod (max_choices + 1);
turn_off(choice[last]);
turn_on(choice[current]);
end;
until c = cr; {end repeat}
get_choice := current;
end; {get_choice}
begin
initialize_choices;
display_choices;
result := get_choice;
gotoxy(20,20);
write(result:1, ' was your choice.');
end.